
#define ADB_TIMEOUT		10000

extern char Scratch8[]	:	0x9FA;

ADBComplete(){
	*(char *)Scratch8 = TRUE;
}


ADBIndAvail(index)
	short				index;
	{
		ADBAddress		addrs;
		ADBDataBlock	devBlock;
		OSErr				err;
		short				cmdNum;
		Str255			ADBData;
	
		addrs = GetIndADB(&devBlock,index);
		cmdNum = ((addrs*16)+0xF);
		ADBData[0] = 0;
		ADBData[1] = 0;
		ADBData[2] = 0;
	
		*(char *)Scratch8 = FALSE;
		err = ADBOp(NIL,ADBComplete,&ADBData,cmdNum);
		if (!err){
			short I= 0;
		
			do
				if (++I > ADB_TIMEOUT) *(char *)Scratch8 = TRUE; 
			while (!*(char *)Scratch8);
		
			if (ADBData[0] != 0) return (TRUE);
	}
	
	return (FALSE);
}


#include "MacTypes.h"
#include "HyperXCmd.h"
#include "DeskBus.h"
#include "SetUpA4.h"

#define ADB_KEYBOARD		2
#define ADB_MOUSE			3

#define STANDARD_KBD		1
#define EXTENDED_KBD		2

#define MAX_ADB_DEVICES	16

pascal main(paramPtr)
   XCmdBlockPtr	paramPtr;
   {
   Str255			str;
   short				ix;
   
   RememberA0();
   SetUpA4();
   
   if(paramPtr->paramCount == 1){
   	ZeroToPas(paramPtr,*((unsigned char **)paramPtr->params[0]),str);
      if (str[0] == 1){
      	if (str[1] == '?') 
				pstrcpy(str,"\pKBDAvail()");
      	else if (str[1] == '!') 
				pstrcpy(str,"\pv1.0; © Pharos Technologies, Inc. 1989");
      }
      goto Done;
  	}
   
   if (!ADBExists()){ 
		pstrcpy(str,"\p0\rnoADB"); 
		goto Done; 
	}
   	
	for ( ix  =1; ix <=MAX_ADB_DEVICES; ix ++){
		ADBDataBlock		ADBinfo;
		ADBAddress			ADBaddr;
		
		if (!ADBIndAvail( ix )) continue;
		ADBaddr = GetIndADB(&ADBinfo,I);
		if (ADBaddr <= 0) continue;
		if (ADBinfo.origADBAddr == ADB_MOUSE){ 
			pstrcpy(str,"\ptrue"); 
			goto Done; 
		}
	}
	pstrcpy(str,"\pfalse");
		
Done:
   paramPtr->returnValue = PasToZero(paramPtr,(StringPtr)str);
   RestoreA4();
}

#include "MacTypes.h"
#include "HyperXCmd.h"
#include "DeskBus.h"
#include "SetUpA4.h"

#define ADB_KEYBOARD		2
#define ADB_MOUSE			3

#define STANDARD_KBD		1
#define EXTENDED_KBD		2

#define MAX_ADB_DEVICES	16


pascal main(paramPtr)
   XCmdBlockPtr	paramPtr;
   {
   Str255			str;
   short				I;
   
   RememberA0();
   SetUpA4();
   
   if (paramPtr->paramCount == 1){
   	ZeroToPas(paramPtr,*((unsigned char **)paramPtr->params[0]),str);
      if (str[0] == 1){
      	if (str[1] == '?') 
				pstrcpy(str,"\pKBDAvail()");
      	else if (str[1] == '!') 
				pstrcpy(str,"\pv1.0; © Pharos Technologies, Inc. 1989");
      }
      goto Done;
    }
   
   if (!ADBExists()){ 
		pstrcpy(str,"\p0\rnoADB"); 
		goto Done; 
	}
   	
	for (I=1;I<=MAX_ADB_DEVICES;I++){
		ADBDataBlock		ADBinfo;
		ADBAddress			ADBaddr;
		
		if (!ADBIndAvail(I)) continue;
		ADBaddr = GetIndADB(&ADBinfo,I);
		if (ADBaddr <= 0) continue;

		if (ADBinfo.origADBAddr == ADB_KEYBOARD){
			if (ADBinfo.devType == STANDARD_KBD){ 
				pstrcpy(str,"\ptrue,standard"); 
				goto Done; 
			}
			else if (ADBinfo.devType == EXTENDED_KBD){ 
				pstrcpy(str,"\ptrue,extended"); 
				goto Done; 
			}
			else{ 
				pstrcpy(str,"\ptrue,unknown"); 
				goto Done; 
			}
		}

	}
	pstrcpy(str,"\pfalse");
		
Done:
   paramPtr->returnValue = PasToZero(paramPtr,(StringPtr)str);
   RestoreA4();
   }


